<template>
    <el-dialog :visible.sync="visible" title="新增" :close-on-click-modal="false" :close-on-press-escape="false" @close="close">
        <el-form :model="dataForm" ref="dataForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px">
            <el-form-item prop="remark" label="PEDC固件描述">
                <el-input v-model="dataForm.remark" placeholder="PEDC固件描述"></el-input>
            </el-form-item>
            <el-form-item prop="PEDCFile" label="PEDC固件文件">
				<el-upload
				    :data="paramsData"
                    v-model="dataForm.PEDCFile"
                    :headers="headers"
					:before-upload="beforeUpload"
                    :action="url"
                    :on-success="handleSuccess"
                    class="upload-demo" 
                    :file-list="fileList"
					:limit="1" style="text-align: left;">
					<el-button size="small" type="primary">点击上传</el-button>
				</el-upload>
			</el-form-item>
        </el-form>
        <template slot="footer">
            <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
            <!-- <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button> -->
        </template>
    </el-dialog>
</template>

<script>
	import Cookies from 'js-cookie'
export default {
    data() {
        return {
            visible:false,
            dataForm:{
			   id:'',
               remark:'',
			   PEDCFile:'',
            },
			headers:{
					  'Authorization':Cookies.get('token')
			},
			url:window.SITE_CONFIG['apiURL']+'/psc/packagemanage/Uploader',
			paramsData:{
				name:'',
				type:'PEDC'
			},
			fileList:[],
        }
    },
    computed:{
        dataRule(){
            return{
                remark:[
                    {required: true, message: 'PEDC固件描述不能为空', trigger: 'blur'}
                ],
                PEDCFile:[
                    {required: true, message: 'PEDC固件文件不能为空', trigger: 'blur'}
                ]
            }
        }
    },
    mounted() {
        
    },
    methods: {
        init(status) {
            this.visible = true
            // if(status){
            //     this.editStatus = status
            // }else{
            //     this.editStatus = false
            // }
            this.$nextTick(() => {
                this.$refs['dataForm'].resetFields()
                
            })
        },
		close(){
			this.fileList = []
		},
		beforeUpload(){
			if(this.dataForm.remark){
				this.paramsData.name = this.dataForm.remark
			}else{
				this.$message({
					message: '请输入PEDC固件描述',
					type: 'error',
					duration: 2000,
				})
				return false
			}
		},
		handleSuccess(res,file,fileList){
			if(res.code==0){
				this.dataForm.PEDCFile = res.data
				this.visible = false
				this.$emit('refreshDataList')
			}
		}
    },
}
</script>

<style scoped>

</style>